//按钮事件新增或编辑
var B7FAE7_type = "";
//其他页面传到本页面参数
var B7FAE7_param = {};
//暂时没用
var B7FAE7_validate = "";
//当前触发按钮
var B7FAE7_btn = "";

/*定义下拉框集合定义*/
/*declare select options begin*/
var B7FAE7_ary_S_STATE = [{"MAIN_ID":"1","CN_NAME":"启用"},{"MAIN_ID":"0","CN_NAME":"禁用"}];
var B7FAE7_ary_AREA_CODE = null;

/*declare select options end*/

//输入框默认值
function B7FAE7_input_default(){

	/*时间格式初始化*/
	/*form datetime init begin*/
    if($("#B7FAE7_CREATE_DATE").val() == "")
    {
        $("#B7FAE7_CREATE_DATE").val(new Date().Format('yyyy-MM-dd hh:mm:ss'));
    }
    laydate.render({
        elem: '#B7FAE7_CREATE_DATE',
        type: 'datetime',
        trigger: 'click'
    });
	
    /*form datetime init end*/
    
	//所有输入框设置默认值
	/*Input Default Begin*/
	$("#B7FAE7_S_SORT").val('0');
	$("#B7FAE7_S_STATE").val('1');	
	/*Input Default End*/
}

//主从表传递参数
function B7FAE7_param_set(){
	/*Main Subsuv Table Param Begin*/
    $("#B7FAE7_find_AREA_CODE_cn_name").val("");
    $("#B7FAE7_find_AREA_CODE").val("");
    $("#B7FAE7_Clear_AREA_CODE").show();
    $("#B7FAE7_Ope_AREA_CODE").show();
    if(B7FAE7_param.hasOwnProperty("AREA_CODE_cn_name"))
        $("#B7FAE7_find_AREA_CODE_cn_name").val(s_decode(B7FAE7_param["AREA_CODE_cn_name"]));
    if(B7FAE7_param.hasOwnProperty("AREA_CODE"))
        $("#B7FAE7_AREA_CODE").val(B7FAE7_param["AREA_CODE"]);
    if(B7FAE7_param.hasOwnProperty("hidden_find") && B7FAE7_param.hasOwnProperty("AREA_CODE_cn_name")){
        $("#B7FAE7_Ope_AREA_CODE").hide();
        $("#B7FAE7_Clear_AREA_CODE").hide();
    }
	/*Main Subsuv Table Param end*/
    
    /*父页面查询条件参数传递至子页面并赋值*/
	/*Get Find Select param bgein*/
	if(B7FAE7_param.hasOwnProperty("LOGIN_ID"))
    	$("#B7FAE7_LOGIN_ID").val(B7FAE7_param["LOGIN_ID"]);
	if(B7FAE7_param.hasOwnProperty("NICK_NAME"))
    	$("#B7FAE7_NICK_NAME").val(B7FAE7_param["NICK_NAME"]);
	if(B7FAE7_param.hasOwnProperty("AREA_CODE"))
    	$("#B7FAE7_AREA_CODE").val(B7FAE7_param["AREA_CODE"]);
	if(B7FAE7_param.hasOwnProperty("AREA_CODE_cn_name"))
    	$("#B7FAE7_find_AREA_CODE_cn_name").val(B7FAE7_param["AREA_CODE_cn_name"]);
	/*Get Find Select param end*/
}

//业务逻辑数据开始
function B7FAE7_t_user_info_biz_start(inputdata) {
	B7FAE7_param = inputdata;
	layer.close(ly_index);
    /*biz begin*/
    var inputdata = {
        "param_name": "N01_t_user_info$AREA_CODE",
        "session_id": session_id,
        "login_id": login_id
    };
    ly_index = layer.load();
    get_ajax_baseurl(inputdata, "B7FAE7_get_N01_t_user_info$AREA_CODE");
	
    /*biz end*/
}

/*biz step begin*/
function B7FAE7_format_S_STATE(value, row, index) {
    var objResult = value;
    for(i = 0; i < B7FAE7_ary_S_STATE.length; i++) {
        var obj = B7FAE7_ary_S_STATE[i];
        if (obj[GetLowUpp("main_id")].toString() == value.toString()) {
            objResult = s_decode(obj[GetLowUpp("cn_name")]);
            break;
        }
    }
    return objResult;
}

function B7FAE7_format_AREA_CODE(value, row, index) {
    var objResult = value;
    for(i = 0; i < B7FAE7_ary_AREA_CODE.length; i++) {
        var obj = B7FAE7_ary_AREA_CODE[i];
        if (obj[GetLowUpp("main_id")].toString() == value.toString()) {
            objResult = s_decode(obj[GetLowUpp("cn_name")]);
            break;
        }
    }
    return objResult;
}

function B7FAE7_get_N01_t_user_info$AREA_CODE(input) {
    layer.close(ly_index);
    //查询失败
    if (Call_QryResult(input.N01_t_user_info$AREA_CODE) == false)
        return false;
    B7FAE7_ary_AREA_CODE = input.N01_t_user_info$AREA_CODE;

    if($("#B7FAE7_S_STATE").is("select") && $("#B7FAE7_S_STATE")[0].options.length == 0)
    {
        $.each(B7FAE7_ary_S_STATE, function (i, obj) {
            addOptionValue("B7FAE7_S_STATE", obj[GetLowUpp("main_id")], s_decode(obj[GetLowUpp("cn_name")]));
        });
    }
    B7FAE7_init_t_user_info();
}

/*biz step end*/

/*查找框函数*/
/*find qry fun begin*/

function B7FAE7_AREA_CODE_cn_name_fun(){
    B7FAE7_btn = "AREA_CODE"
    index_subhtml = "sys_vue/t_code_regions.vue";
    random_subhtml = "AFADBC";
    if(loadHtmlSubVueFun("sys_vue/t_code_regions.vue","B7FAE7_t_user_info_call_vue") == true){
        var n = Get_RandomDiv("AFADBC","");
        layer.open({
            type: 1,
            area: ['1100px', '600px'],
            fixed: false, //不固定
            maxmin: true,
            content: $(n),
            success: function(layero, index){
                $('#AFADBC_t_code_regions_Events').bootstrapTable('resetView');
                AFADBC_param["ly_index"] = index;
                AFADBC_param["target_name"] = "B7FAE7_find_"+B7FAE7_btn+"_cn_name";
                AFADBC_param["target_id"] = "B7FAE7_"+B7FAE7_btn;
                AFADBC_param["sourc_id"] = "AREA_CODE";
                AFADBC_param["sourc_name"] = "AREA_NAME";
            },
            end: function(){
                $(n).hide();
            }
        });
     }
}

/*find qry fun end*/

/*页面结束*/
function B7FAE7_page_end(){
	$("#div_B7FAE7_LOGIN_PWD").show();
	if(B7FAE7_param["type"] == "edit"){
		B7FAE7_get_edit_info();
	}
}

//页面初始化方法
function B7FAE7_init_t_user_info() {
	//输入框默认值
	B7FAE7_input_default();
	//传递参数
	B7FAE7_param_set();
	//表单验证
	B7FAE7_checkFormInput();
	//结束函数
	B7FAE7_page_end();
}

//提交表单数据
function B7FAE7_SubmitForm(){
	if(B7FAE7_param["type"] == "add"){		
		var pwdRegex = new RegExp('(?=.*[0-9])(?=.*[A-Z])(?=.*[a-z])(?=.*[^a-zA-Z0-9]).{8,30}');		 
		if (!pwdRegex.test($("#B7FAE7_LOGIN_PWD").val())) {
			swal("提交失败!", "失败原因:您的密码复杂度太低（密码中必须包含大小写字母、数字、特殊字符）", "warning");
			return false;
		}
		
		var inputdata = {
				"param_name": "N01_ins_t_user_info",
				"session_id": session_id,
				"login_id": login_id
	            /*insert param begin*/
                ,"param_value1": s_encode($("#B7FAE7_LOGIN_ID").val())
                ,"param_value2": s_encode($("#B7FAE7_LOGIN_PWD").val())
                ,"param_value3": s_encode($("#B7FAE7_NICK_NAME").val())
                ,"param_value4": $("#B7FAE7_S_SORT").val()
                ,"param_value5": $("#B7FAE7_S_STATE").val()
                ,"param_value6": $("#B7FAE7_CREATE_DATE").val()
                ,"param_value7": s_encode($("#B7FAE7_S_DESC").val())
                ,"param_value8": s_encode($("#B7FAE7_AREA_CODE").val())
				
	            /*insert param end*/
			};
		get_ajax_baseurl(inputdata, "B7FAE7_get_N01_ins_t_user_info");
	}
	else if(B7FAE7_param["type"] == "edit"){
		var inputdata = {
				"param_name": "N01_upd_t_user_info",
				"session_id": session_id,
				"login_id": login_id
	            /*update param begin*/
                ,"param_value1": s_encode($("#B7FAE7_LOGIN_ID").val())
                ,"param_value2": s_encode($("#B7FAE7_NICK_NAME").val())
                ,"param_value3": $("#B7FAE7_S_SORT").val()
                ,"param_value4": $("#B7FAE7_S_STATE").val()
                ,"param_value5": $("#B7FAE7_CREATE_DATE").val()
                ,"param_value6": s_encode($("#B7FAE7_S_DESC").val())
                ,"param_value7": s_encode($("#B7FAE7_AREA_CODE").val())
                ,"param_value8": $("#B7FAE7_MAIN_ID").val()
				
	            /*update param end*/
			};
		get_ajax_baseurl(inputdata, "B7FAE7_get_N01_upd_t_user_info");
	}
}

//vue回调
function B7FAE7_t_user_info_call_vue(objResult){
	if(index_subhtml == "XXXXXX")
	{
		
	}
	/*查询条件弹窗子页面*/
    /*get find subvue bgein*/
    else if(index_subhtml == "sys_vue/t_code_regions.vue"){
        var n = Get_RandomDiv("AFADBC",objResult);
        layer.open({
            type: 1,
            area: ['1100px', '600px'],
            fixed: false, //不固定
            maxmin: true,
            content: $(n),
            success: function(layero, index){
                var inputdata = {
                    "type":B7FAE7_type,
                    "ly_index":index,
                    "target_name":"B7FAE7_find_AREA_CODE_cn_name",
                    "target_id":"B7FAE7_AREA_CODE",
                    "sourc_id":"AREA_CODE",
                    "sourc_name":"AREA_NAME"
                };
                loadScript_hasparam("sys_vue/t_code_regions.js","AFADBC_t_code_regions_biz_start",inputdata);
            },
            end: function(){
                $(n).hide();
            }
        });
    }
	
	/*get find subvue end*/
}

//for表单提交
$("#B7FAE7_save_t_user_info_Edit").click(function () {
	$("form[name='B7FAE7_DataModal']").submit();
})

/*修改数据*/
function B7FAE7_get_N01_upd_t_user_info(input) {
	layer.close(ly_index);
	if (Call_OpeResult(input.N01_upd_t_user_info) == true)
	{
		swal("修改数据成功!", "", "success");
		A7FAE7_t_user_info_query();
		B7FAE7_clear_validate();
		layer.close(B7FAE7_param["ly_index"]);
	}
}

/*添加数据*/
function B7FAE7_get_N01_ins_t_user_info(input) {
	layer.close(ly_index);
	if (Call_OpeResult(input.N01_ins_t_user_info) == true)
	{
		swal("添加数据成功!", "", "success");
		A7FAE7_t_user_info_query();
		B7FAE7_clear_validate();
		layer.close(B7FAE7_param["ly_index"]);
	}
}

//取消编辑
$("#B7FAE7_cancel_t_user_info_Edit").click(function () {
	layer.close(B7FAE7_param["ly_index"]);
	B7FAE7_clear_validate();
	$("[id^='B7FAE7_div']").hide();
})

//清除查找框
function B7FAE7_clear_input_cn_name(obj1,obj2){
	$("#"+obj1).val("");
	$("#"+obj2).val("-1");
}

//清除验证缓存
function B7FAE7_clear_validate(){
	$("#B7FAE7_DataModal").find(".has-error").each(function(){
		$(this).removeClass('has-error');
	});
	$("#B7FAE7_DataModal").find(".has-success").each(function(){
	 	$(this).removeClass('has-success');
	});
	$("#B7FAE7_DataModal").find(".glyphicon").each(function(){
	 	$(this).remove();
	});
}

//输入框重置
function B7FAE7_clear_edit_info(){
	var inputs = $("#B7FAE7_DataModal").find('input');
	var selects = $("#B7FAE7_DataModal").find("select");
	var textareas = $("#B7FAE7_DataModal").find('textarea');
	var divs = $("div[id^='B7FAE7'][id$='FILE_div']");  
	$.each(inputs, function (i, obj) {
		$(obj).val("");
	});
	$.each(selects, function (i, obj) {
		$(obj).val("");
	});
	$.each(textareas, function (i, obj) {
		$(obj).val("");
	});
	$.each(divs, function (i, obj) {
		$(obj).html("");
	});
	/*清除输入框验证信息*/
	/*input validate clear begin*/
    B7FAE7_clear_input_cn_name('B7FAE7_find_AREA_CODE_cn_name','B7FAE7_AREA_CODE')
	
	/*input validate clear end*/
	B7FAE7_init_t_user_info();
}

//页面输入框赋值
function B7FAE7_get_edit_info(){
	var rowData = $("#A7FAE7_t_user_info_Events").bootstrapTable('getData')[A7FAE7_select_t_user_info_rowId];
	var inputs = $("#B7FAE7_DataModal").find('input');
	var selects = $("#B7FAE7_DataModal").find("select");
	var textareas = $("#B7FAE7_DataModal").find('textarea');
	
	//通用子页面输入框赋值
	Com_edit_info(rowData,inputs,selects,textareas,"A7FAE7","B7FAE7");
	
	//树型结构父类赋值
	/*tree pid set value begin*/
	$("#B7FAE7_find_AREA_CODE_cn_name").val(B7FAE7_format_AREA_CODE(rowData["AREA_CODE"],"",0));
	$("#div_B7FAE7_LOGIN_PWD").hide();
	/*tree pid set value end*/
	
	/*文件附件格式*/
	/*input param fileinfo begin*/
	
	/*input param fileinfo end*/
}

//form验证
function B7FAE7_checkFormInput() {
    B7FAE7_validate = $("#B7FAE7_DataModal").validate({
        errorElement: 'span',
        errorClass: 'help-block',
        rules: {
        	/*input check rules begin*/
            B7FAE7_MAIN_ID: {}
            ,B7FAE7_LOGIN_ID: {maxlength:50}
            ,B7FAE7_LOGIN_PWD: {maxlength:50}
            ,B7FAE7_NICK_NAME: {maxlength:20}
            ,B7FAE7_S_SORT: {digits: true,required : true,maxlength:10}
            ,B7FAE7_S_STATE: {}
            ,B7FAE7_CREATE_DATE: {date: true,required : true,maxlength:19}
            ,B7FAE7_S_DESC: {maxlength:500}
            ,B7FAE7_AREA_CODE: {maxlength:50}
			
            /*input check rules end*/
        },
        messages: {
        	/*input check messages begin*/
            B7FAE7_MAIN_ID: {}
            ,B7FAE7_LOGIN_ID: {maxlength:"长度不能超过50"}
            ,B7FAE7_LOGIN_PWD: {maxlength:"长度不能超过50"}
            ,B7FAE7_NICK_NAME: {maxlength:"长度不能超过20"}
            ,B7FAE7_S_SORT: {digits: "必须输入整数",required : "必须输入整数",maxlength:"长度不能超过10" }
            ,B7FAE7_S_STATE: {}
            ,B7FAE7_CREATE_DATE: {date: "必须输入正确格式的日期",required : "必须输入正确格式的日期",maxlength:"长度不能超过19"}
            ,B7FAE7_S_DESC: {maxlength:"长度不能超过500"}
            ,B7FAE7_AREA_CODE: {maxlength:"长度不能超过50"}
			
            /*input check messages end*/
        },
        errorPlacement: function (error, element) {
            element.next().remove();
            element.after('<span class="glyphicon glyphicon-remove form-control-feedback" aria-hidden="true"></span>');
            element.closest('.form-group').append(error);
        },
        highlight: function (element) {
            $(element).closest('.form-group').addClass('has-error has-feedback');
        },
        success: function (label) {
            var el = label.closest('.form-group').find("input");
            el.next().remove();
            el.after('<span class="glyphicon glyphicon-ok form-control-feedback" aria-hidden="true"></span>');
            label.closest('.form-group').removeClass('has-error').addClass("has-feedback has-success");
            label.remove();
        },
        submitHandler: function (form) {
        	B7FAE7_SubmitForm();
        	return false;
        }
    })
}